const wechat_img = "http://m.360buyimg.com/n1/s120x120_jfs/t17287/163/2164403206/7237/2e30ddeb/5aeaff46Nbffbe4fa.jpg";

const globalHistory = window.history;
const UA = navigator.userAgent;

const getQueryString = name => {
  var reg = new RegExp('(^|&|\\?)' + name + '=([^(&|#)]*)', 'i');
  var r = location.href.match(reg);
  if (r != null) {
    return decodeURIComponent(r[2]);
  }
  return "";
}

const go = pageName => {
  let url = location.href.replace(/\?.*/, "").replace(/#.*/, "");
  location.href = url + "#" + pageName;
}

const goBack = () => {
  return this.go(-1);
}

const getCookie = name => {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if (arr = document.cookie.match(reg))
    return decodeURI(arr[2]);
  else
    return '';
}

const setCookie = (e, t, n, o = null, i = null) => {
  var r = 300,
    a = new Date();
  i ? a = i : a.setTime(a.getTime() + 24 * r * 60 * 60 * 1e3),
    document.cookie = e + "=" + t + ";expires=" + a.getTime() + (n ? ";domain=" + n : "") + ";path=" + (o ? o : "/")
};

const delCookie = name => {
  /*let exp = new Date();
  exp.setTime(exp.getTime() - 1);
  let cval = getCookie(name);
  if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();*/
  return setCookie(name, null);
}

const sub = (str, n, speSymbol = '') => {
  var r = /[^\x00-\xff-Z0-9]/g;
  if (str.replace(r, "mm").length <= n) {
    return str;
  }
  var m = Math.floor(n / 2);
  for (var i = m; i < str.length; i++) {
    if (str.substr(0, i).replace(r, "mm").length >= n) {
      return str.substr(0, i) + speSymbol;
    }
  }
  return str;
}


const getOpenId = () => {
  return getCookie('sq_open_id') || getCookie('open_id') || -1;
}

const getEid = () => {
  let fingerInfo;
  let callBackFingerInfo = function (info) {
    fingerInfo = info;
  }

  if (isIOS()) {
    let iswk = (-1 != UA.indexOf("supportJDSHWK/1")) || (window._is_jdsh_wkwebview == 1);
    if (iswk) {
      let obj = {
        method: "getFingerInfo",
        params: callBackFingerInfo
      }
      try {
        fingerInfo = window.webkit.messageHandlers.JDAppUnite.postMessage(obj);
      } catch (e) {
        fingerInfo = typeof e == 'object' ? (e && e.toString()) : e;
        ;
      }
    } else {
      try {
        fingerInfo = window.JDAppUnite && window.JDAppUnite.getFingerInfo(callBackFingerInfo);
      } catch (e) {
        fingerInfo = typeof e == 'object' ? (e && e.toString()) : e;
        ;
      }
    }
  } else if (isAndroid()) {
    try {
      fingerInfo = window.JDAppUnite && window.JDAppUnite.getFingerInfo(callBackFingerInfo);
    } catch (e) {
      fingerInfo = typeof e == 'object' ? (e && e.toString()) : e;
      ;
    }
  } else {
    fingerInfo = window.risk_jd && window.risk_jd.eid || -1;
  }

  return fingerInfo;
}

const getFp = () => {
  return window.risk_jd && window.risk_jd.fp || -1;
}

const getShshshfp = () => {
  let shshshfp = -1;
  try {
    shshshfp = fp.get();
  } catch (e) {
  }
  return getCookie('shshshfp') || shshshfp;
}

const getShshshfpa = () => {
  return getCookie('shshshfpa') || -1;
}

const getShshshfpb = () => {
  return getCookie('getShshshfpb') || -1;
}

const getClient = () => {
  let client = -1;
  if (isAndroid()) client = 'Android';
  if (isIPhone()) client = 'Iphone';
  // if (isIpad()) client = 'Ipad';
  return client;
}



const getBrand = () => {
  let brand;
  if (isAndroid()) {
    brand = -1;
  } else if (isIOS()) {
    brand = 'iphone';
    // } else if (isIpad()) {
    //     brand = ipad;
  } else {
    brand = -1;
  }
  return brand;
}

const getModel = () => {
  return -1;
}



export default {

}
